home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-12-12 | 2.0 KB | 93 lines |
- /*
- * Copyright(C) 1996 Sony Corporation. All rights reserved.
- */
-
- import vrml.*;
- import vrml.field.*;
- import vrml.node.*;
- import java.util.*;
- import vs.*;
-
- public class luck extends Script{
- /* Node */
- SFNode LuckNode;
-
- /* EventOut */
- SFRotation LuckTransformRotation;
- SFColor LuckMaterialColor;
-
- float LuckRot = 0.0f;
- static int R = 0;
- static int G = 1;
- static int B = 2;
-
- static int X = 0;
- static int Y = 1;
- static int Z = 2;
- static int DEGREE = 3;
-
- public void initialize() {
- /* Node */
- LuckNode = (SFNode) getField( "LuckNode" );
-
- /* EventOut */
- LuckTransformRotation = (SFRotation) getEventOut( "LuckTransformRotation" );
- LuckMaterialColor = (SFColor) getEventOut( "LuckMaterialColor" );
- }
-
- public void processEvent(Event e) {
- String name = e.getName () ;
-
- if(name.equals("LuckTouchSensorIsActive")) { LuckTouchSensorIsActive(e); }
- if(name.equals("LuckShareTouched")){ LuckShareTouched(e); }
- }
-
- public void LuckTouchSensorIsActive(Event e) {
- double time = e.getTimeStamp();
- ConstSFBool mouse_down = (ConstSFBool)e.getValue();
-
- if (mouse_down.getValue()) return; /* mouseDown */
-
- LuckStart( time );
- Vscp.sendApplSpecificMsgWithDist( LuckNode, "LuckShareTouched", "void", Vscp.allClientsExceptMe );
- }
-
- public void LuckShareTouched(Event e) {
- double time = e.getTimeStamp();
-
- LuckStart( time );
-
- }
-
- public void LuckStart ( double time ) {
- float rot[] = new float[4];
- float col[] = new float[3];
-
- col[R] = (float)randMinMax(0, 255) / 255.0f;
- col[G] = (float)randMinMax(0, 255) / 255.0f;
- col[B] = (float)randMinMax(0, 255) / 255.0f;
- LuckMaterialColor.setValue( col );
- LuckRot = LuckRot + 1.04f;
- rot[X] = 0.0f;
- rot[Y] = 0.0f;
- rot[Z] = 1.0f;
- rot[DEGREE] = LuckRot;
- LuckTransformRotation.setValue( rot );
-
- }
-
- int randMinMax(int min,int max){
- int value;
- int range;
- double rnd;
-
- range = max - min;
- rnd = Math.random();
- value = (int)(rnd * (double)range) + min;
-
- return value;
- }
-
- }
-